package wifiunion.com.notice.service;

import android.app.IntentService;
import android.content.Intent;
import android.support.annotation.Nullable;

import java.util.HashMap;

import wifiunion.com.notice.BaseCallBack;
import wifiunion.com.notice.Constants;
import wifiunion.com.notice.HttpUtils;
import wifiunion.com.notice.utils.SharedPreferencesUtils;


/**
 * Created by Administrator on 2018/9/14.
 */

public class AuthtokenIntentService extends IntentService {
    /**
     * Creates an IntentService.  Invoked by your subclass's constructor.
     *
     * @param name Used to name the worker thread, important only for debugging.
     */
    public AuthtokenIntentService(String name) {
        super(name);
    }
    public AuthtokenIntentService() {
        super("AuthtokenIntentService");
    }


    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        try {
            final String mAuthtoken = SharedPreferencesUtils.getSharedPreferences(Constants.CONFIG_AUTHTOKEN,getApplicationContext());
            new Thread(new Runnable() {
                @Override
                public void run() {
                    HashMap<String, Object> params = new HashMap<String, Object>();
                    params.put("Authorization", mAuthtoken);
                    HttpUtils.HttpGetRequest_Asyn(Constants.HTTP_URL_GET_REFRESH_AUTHTOKEN, params, new BaseCallBack() {
                        @Override
                        public void onSuccess(Object data) {

                        }

                        @Override
                        public void onServerFailed(Object errorObj) {

                        }

                        @Override
                        public void onNetFailed() {

                        }
                    }, null);
                }
            }).start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
